package Java8;

import java.util.ArrayList;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public class Teacher {
    private List<Student> student;

    public Teacher() {
        student = new ArrayList<>();
        Student s1 = new Student("a", "1001");
        Student s2 = new Student("b", "1002");
        Student s3 = new Student("c", "1003");
        Student s4 = new Student("d", "1004");
        student.add(s1);
        student.add(s2);
        student.add(s3);
        student.add(s4);
    }

    private static List<Student> getStudents(String str) {
        return new Teacher().student;
    }

    public static void main(String[] args) {
        Function<String, List<Student>> fun = Teacher::getStudents;
        List<Student> list = fun.apply("123");
        //List<String> result = list.stream().flatMap(student->student.getList().stream())
        //		.filter(student->student.compareTo("11")>0).collect(Collectors.toList());
//		List<String> result = list.stream().filter(student->student.getId().compareTo("1001")>0)
//		.map(student->student.getName()).collect(Collectors.toList());
        IntSummaryStatistics result = list.stream().filter(student -> student.getId().compareTo("1001") > 0)
                .mapToInt(student -> Integer.valueOf(student.getId())).summaryStatistics();
        System.out.println(result);
        Optional<String> opt = Optional.ofNullable(null);
        System.out.println(opt.isPresent());
        System.out.println(opt.orElseGet(() -> "abv"));
    }
}

class Student {
    private String name;
    private String id;
    private List<String> list = new ArrayList<>();

    public Student(String name, String id) {
        super();
        this.name = name;
        this.id = id;
        list.add("10");
        list.add("11");
        list.add("12");
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

}
